package control;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import model.business.Item;
import model.business.LogicFacade;
import model.business.Orcamento;
import model.database.AccessDAOFactory;
import model.database.DAOFactory;
import model.database.OrcamentoDAO;

public class Conversor {

	private  static DAOFactory AccessDAOFactory;
	private static DAOFactory postgreFactory;
	private static OrcamentoDAO aDAO;
	private static OrcamentoDAO pDAO;
	private static LogicFacade lf;

	public Conversor(){
	

	}

	public static void main(String[] args){
		AccessDAOFactory = new AccessDAOFactory();
		aDAO = AccessDAOFactory.getOrcamentoDAO();

		List l = aDAO.getOrdemLista(null);
		Resource res = new ClassPathResource("database.xml");
		BeanFactory factory= new XmlBeanFactory(res);
		lf= (LogicFacade) factory.getBean("logicFacade");
		postgreFactory=lf.getPostgreFactory();
		pDAO= postgreFactory.getOrcamentoDAO();
		Iterator i = l.iterator();
		while (i.hasNext()){
			Orcamento oc=(Orcamento)i.next();
			//List itens=oc.getItem();
			//oc.setItem(null);
			pDAO.insertOrdem(oc);		
			//Iterator iitem=itens.iterator();
			//while (iitem.hasNext()){
			//	pDAO.insertItem((Item) iitem.next());
			//}
		}
		
	}
	
	public DAOFactory getAccessDAOFactory() {
		return AccessDAOFactory;
	}
	public void setAccessDAOFactory(DAOFactory accessDAOFactory) {
		AccessDAOFactory = accessDAOFactory;
	}
	public DAOFactory getPostgreFactory() {
		return postgreFactory;
	}
	public void setPostgreFactory(DAOFactory postgreFactory) {
		this.postgreFactory = postgreFactory;
	}

	
	
}
